//
//  MeKey.swift
//  mng
//
//  Created by WTFKL on 2018/4/3.
//  Copyright © 2018年 WTF. All rights reserved.
//

import UIKit
import SpriteKit
class MeKey: SKSpriteNode {
    
    convenience init(mName:String,posistion:CGPoint) {
        //钥匙
        self.init();
        self.texture = SKTexture(image: #imageLiteral(resourceName: "key"));
        self.size = CGSize(width: 20, height: 20);
        self.position = posistion;
        self.physicsBody = SKPhysicsBody(rectangleOf:self.size);
        self.physicsBody?.isDynamic = false;
        self.physicsBody?.categoryBitMask = BitMaskType.key;
        self.physicsBody?.contactTestBitMask = BitMaskType.charactor;
       
        let action1 = SKAction.move(to: CGPoint.init(x: self.position.x, y: self.position.y+10), duration: 0.5);
        let action2 = SKAction.move(to: CGPoint.init(x: self.position.x, y: self.position.y-10), duration: 0.5);
        let qence = SKAction.sequence([action1,action2]);
        let run = SKAction.repeatForever(qence);
        self.run(run);
    }
}
